package com.chixing.service.impl;

import com.chixing.pojo.Mycoupons;
import com.chixing.pojo.Myorder;
import com.chixing.service.OrderService;
import com.chixing.util.ServerResponse;
import org.hibernate.criterion.Order;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author YHB
 * @date 2021/11/2  22:01
 */
@Service
public class MsgSender {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private OrderService orderService;

    
    public void addPurchaseOrderMsg(Long purchaseOrderCode,long delayedTime){

       Myorder myorder = orderService.getByOrderNum(purchaseOrderCode);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        CorrelationData correlationData = new CorrelationData(String.valueOf(purchaseOrderCode));
        rabbitTemplate.convertAndSend("ORDER_EXCHANGE", "ORDER.KEY", myorder,
                message -> {
                    // 设置5秒过期
                    message.getMessageProperties().setHeader("x-delay",delayedTime * 1000);
                    return message;
                },
                correlationData);
        System.out.println( "团购订单延迟发送成功：" + sdf.format(new Date()));
    }


    //优惠券
//    public void addMyCouponMsg(Mycoupons mycoupons,long delayedTime){
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        CorrelationData correlationData = new CorrelationData(String.valueOf(mycoupons.ge))
//    }

}
